<?php
class DummyLink extends BankLink {
	
	/**
	* Private key.
	* @var String
	*/
	protected $privateKey;

	public function sendToBank( $callBackId, BankPayment $payment ) {
		if( $this->usable !== true )
			throw new RuntimeException('Using dummy bank is not allowed!');
		
		$mac = $this->calculateMac($callBackId, $payment->price, $payment->uid );
		
		// send user to callback address
		header('location: '.$this->callbackUrl.'&logId='.$callBackId.'&uid='.$payment->uid.'&price='.$payment->price.'&fromDummy=dummy&mac='.$mac);
		
		/*$html = '<input type="hidden" name="logId" value="'.$callBackId.'">
				<input type="hidden" name="uid" value="'.$payment->uid.'">
				<input type="hidden" name="price" value="'.$payment->price.'">
				<input type="hidden" name="fromDummy" value="dummy">
				<input type="hidden" name="mac" value="'.$mac.'">';
		
		echo self::getFormBase($this, $html);
		die();
		*/
	}
	
	public function handleCallback() {
		$mac = $this->calculateMac( $_REQUEST['logId'], $_REQUEST['price'], $_REQUEST['uid'] );
		if( $mac != $_REQUEST['mac'] ) {
			return array('status' => 4, 'logId' => $_REQUEST['logId'], 'bankError'=>'', 'bankErrorStr'=>'');
		} else {
			return array('status' => 1, 'logId' => $_REQUEST['logId'], 'bankError'=>'', 'bankErrorStr'=>'');
		}
	}
	
	public function calculateMac( $callBackId, $price, $uid ){
		return md5(sha1(md5($this->privateKey.'|'.$callbackId.'|'.$price.'|'.$uid.'|dummy')));
	}
	
	
}
?>